package no.ffi.gismoidm.pubsub;

import java.io.Serializable;
import no.ffi.gismoidm.utils.IdentityStatement;
import no.fongen.os.FIFO;

/**
 * Abstract class for all neighbors (clients and MRs)
 * 
 * @author anders
 */
public abstract class MessageNeighbor implements java.io.Serializable {
    protected String messageNeighborID;
    protected transient FIFO outwardMessages;
    protected IdentityStatement peerIS;
    
    public boolean equals(Object o) {
        if (!(o instanceof MessageNeighbor)) return false;
        MessageNeighbor otherMR = (MessageNeighbor)o;
        return otherMR.messageNeighborID.equals(messageNeighborID);
    }
    
    public abstract void receiveMessage(Object message);
    
    public String getId() { return messageNeighborID; }
    
    public void sendMessageTo(Serializable message) {
        if (outwardMessages!=null) outwardMessages.nonblockput(message);
    }
    
    public abstract void terminateClient();
}
